package com.stockz.ui.swing.charting.model;

import java.awt.Graphics2D;
import java.awt.Rectangle;

import com.stockz.ui.swing.charting.painter.shape.LinePainter;
import com.stockz.ui.swing.charting.view.StockChartPanel;


public class Line extends Shape {

	private Point start;
	private Point end;
	
	public Line(StockChartPanel stockChartPanel){
		this(stockChartPanel, new Point(stockChartPanel),new Point(stockChartPanel));
	}
	
	public Line(StockChartPanel stockChartPanel,Point start, Point end){
		this(stockChartPanel, start,end,true);
	}
	
	public Line(StockChartPanel stockChartPanel, Point start, Point end, boolean visible) {
		super(stockChartPanel);
		this.start = start;
		this.end = end;
		this.visible = visible;
	}

	@Override
	public void paint(Graphics2D g, Rectangle rectangle) {
		LinePainter.paint(g, this, rectangle);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Line){
			Line line = (Line)obj;
			return line != null 
			&& line.getStart() != null 
			&& line.getEnd() != null 
			&& line.getStart().equals(getStart())
			&& line.getEnd().equals(getEnd());
			
		}else
			return false;
	}
	
	@Override
	public int hashCode() {
		return (String.valueOf(getStart().hashCode())+String.valueOf(getEnd().hashCode())).hashCode();
	}
	
	@Override
	public String toString() {
		return "Line - ["+start == null?"null":start.toString()+", "+end == null?"null":end.toString()+"]";
	}
	
	
	public Point getStart() {
		return start;
	}
	public void setStart(Point start) {
		this.start = start;
	}
	public Point getEnd() {
		return end;
	}
	public void setEnd(Point end) {
		this.end = end;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	
	
}
